using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration; using Sispe.Entities;

namespace Sispe.Repository.Mapping
{
    public class TELEFONOMap : EntityTypeConfiguration<TELEFONO>
    {
        public TELEFONOMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Numero)
                .IsRequired()
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("TELEFONO");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Dni).HasColumnName("Dni");  
            this.Property(t => t.Numero).HasColumnName("Numero");
            this.Property(t => t.IdLineaTelefonica).HasColumnName("IdLineaTelefonica");

            // Relationships
            this.HasOptional(t => t.LINEA_TELEFONICA)
                .WithMany(t => t.TELEFONOes)
                .HasForeignKey(d => d.IdLineaTelefonica);
            this.HasRequired(t => t.PERSONAs)
                .WithMany(t => t.TELEFONOS)
                .HasForeignKey(d => d.Dni);
        }
    }
}
